package com.some;

public class SingleTest {
    SingleTest() {
    }

    private static volatile SingleTest singleTest = null;

    public SingleTest getSingleTest() {
        // 针对多个线程想同时创建对象
        if (singleTest == null) {
            synchronized (SingleTest.class) {
                // 第一个线程创建对象完成，第二个线程等待
                if (singleTest == null) {
                    singleTest = new SingleTest();
                }
            }
        }
        return singleTest;
    }
}
